/* My (demuredemeanor) sofle RGB conf */

/// Pin out /// {{{
/*
 * Bottom View
 *                                     RIGHT                          LEFT
 * ,-----------------------------------------.                      ,-----------------------------------------.
 * |                                         |                      |                                         |
 * | [39]          [38]          [37]        |                      |        [ 0]          [ 1]          [ 2] |
 * |                                         |                      |                                         |
 * |                                         |                      |                                         |
 * |                                         |                      |                                         |
 * | [40]          [41]          [42]        |-------.      ,-------|        [ 5]          [ 4]          [ 3] |
 * |                                                 |      |                                                 |
 * `------------ [43]                            [44] \    / [ 7]                            [ 6] ------------'
 *              \                                     /    \                                     /
 *               `-----------------------------------'      `-----------------------------------'
 */

/*
 * Top View
 *                                      LEFT                         RIGHT
 * ,-----------------------------------------.                      ,-----------------------------------------.
 * |  33  |  32  |  24  |  23  |  14  |  13  |                      |  50  |  51  |  60  |  61  |  69  |  70  |
 * |------+------+------+------+------+------|                      |------+------+------+------+------+------|
 * |  34  |  31  |  25  |  22  |  15  |  12  |                      |  49  |  52  |  59  |  62  |  68  |  71  |
 * |------+------+------+------+------+------|                      |------+------+------+------+------+------|
 * |  35  |  30  |  26  |  21  |  16  |  11  |                      |  48  |  53  |  58  |  63  |  67  |  72  |
 * |------+------+------+------+------+------|-------.      ,-------|------+------+------+------+------+------|
 * |  36  |  29  |  27  |  20  |  17  |  10  |       |      |       |  47  |  54  |  57  |  64  |  66  |  73  |
 * `-------------+------+------+------\------\--------\    /--------/------/------+------+------+-------------'
 *              \|  28  |  19  |  18  |   9   \   8   /    \   45  /   46  |  55  |  56  |  65  |/
 *               `-----------------------------------'      `-----------------------------------'
 *     | -    ^      | -    ^      |-     ^                             ^     -|      ^     -|      ^     -|
 *     v      | -    v      | -    v      |-                           -|      v     -|      v     -|      v
 */
/// End Pin Out /// }}}

/// Layer Colors /// {{{
// Caps Lock
const rgblight_segment_t PROGMEM my_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    // Right Edge
    {2, 2, HSV_RED},
    {33, 4, HSV_RED},
    // Left Edge
    {39, 2, HSV_RED},
    {70, 4, HSV_RED}
);

// Colemak -- Unused
const rgblight_segment_t PROGMEM my_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    {9, 2, HSV_CYAN}
);

// Game
const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    {8, 1, HSV_PURPLE},     // Game Space
    {28, 1, HSV_PURPLE},    // Game Enter
    // WASD
    {21, 1, HSV_PURPLE},
    {25, 2, HSV_PURPLE},
    {30, 1, HSV_PURPLE},
    // Arrows
    {64, 1, HSV_PURPLE},
    {66, 2, HSV_PURPLE},
    {73, 1, HSV_PURPLE},
    // Under Glow
    {6, 2, HSV_PURPLE},
    {44, 2, HSV_PURPLE}
);

// Mouse
const rgblight_segment_t PROGMEM my_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    // Move Mouse
    {48, 1, HSV_YELLOW},
    {53, 1, HSV_YELLOW},
    {58, 1, HSV_YELLOW},
    {63, 1, HSV_YELLOW},
    // Mouse Buttons
    {55, 2, HSV_YELLOW},
    {70, 1, HSV_RED}
);

// Lower
const rgblight_segment_t PROGMEM my_layer4_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    // Left Underglow
    {0, 1, HSV_GREEN},
    {5, 1, HSV_MAGENTA},
    {7, 1, HSV_GREEN},
    // Left Per key
    {8, 1, HSV_GREEN},
    {9, 1, HSV_MAGENTA},
    {10, 1, HSV_GREEN},
    {11, 1, HSV_MAGENTA},
    {12, 1, HSV_GREEN},
    {13, 1, HSV_MAGENTA},
    // Right Underglow
    {37, 1, HSV_GREEN},
    {42, 1, HSV_MAGENTA},
    {44, 1, HSV_GREEN},
    // Right Per key
    {45, 1, HSV_GREEN},
    {46, 1, HSV_MAGENTA},
    {47, 1, HSV_GREEN},
    {48, 1, HSV_MAGENTA},
    {49, 1, HSV_GREEN},
    {50, 1, HSV_MAGENTA}
);

// Raise
const rgblight_segment_t PROGMEM my_layer5_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    // Left Underglow
    {0, 1, HSV_YELLOW},
    {5, 1, HSV_BLUE},
    {7, 1, HSV_YELLOW},
    // Left Per key
    {8, 1, HSV_YELLOW},
    {9, 1, HSV_BLUE},
    {10, 1, HSV_YELLOW},
    {11, 1, HSV_BLUE},
    {12, 1, HSV_YELLOW},
    {13, 1, HSV_BLUE},
    // Right Underglow
    {37, 1, HSV_YELLOW},
    {42, 1, HSV_BLUE},
    {44, 1, HSV_YELLOW},
    // Right Per key
    {45, 1, HSV_YELLOW},
    {46, 1, HSV_BLUE},
    {47, 1, HSV_YELLOW},
    {48, 1, HSV_BLUE},
    {49, 1, HSV_YELLOW},
    {50, 1, HSV_BLUE}
);

// Adjust
const rgblight_segment_t PROGMEM my_layer6_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    // Left Underglow
    {0, 1, HSV_RED},
    {5, 1, HSV_PINK},
    {7, 1, HSV_RED},
    // Left Per key
    {8, 1, HSV_RED},
    {9, 1, HSV_PINK},
    {10, 1, HSV_RED},
    {11, 1, HSV_PINK},
    {12, 1, HSV_RED},
    {13, 1, HSV_PINK},
    // Right Underglow
    {37, 1, HSV_RED},
    {42, 1, HSV_PINK},
    {44, 1, HSV_RED},
    // Right Per key
    {45, 1, HSV_RED},
    {46, 1, HSV_PINK},
    {47, 1, HSV_RED},
    {48, 1, HSV_PINK},
    {49, 1, HSV_RED},
    {50, 1, HSV_PINK}
);
/// End Layer Colors /// }}}

/// Prep /// {{{
// Now define the array of layers. Later layers take precedence
const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
    my_capslock_layer,
    my_layer1_layer,    // Overrides caps lock layer
    my_layer2_layer,    // Overrides other layers
    my_layer3_layer,    // Overrides other layers
    my_layer4_layer,    // Overrides other layers
    my_layer5_layer,    // Overrides other layers
    my_layer6_layer     // Overrides other layers
);

void keyboard_post_init_user(void) {
    // Enable the LED layers
    rgblight_layers = my_rgb_layers;
}
/// End Prep /// }}}

/// Enact Colors~ /// {{{
bool led_update_user(led_t led_state) {
    rgblight_set_layer_state(0, led_state.caps_lock);
    return true;
}

layer_state_t default_layer_state_set_user(layer_state_t state) {
    // Not setting colemak
    /*rgblight_set_layer_state(1, layer_state_cmp(state, _COLEMAK));*/
    rgblight_set_layer_state(2, layer_state_cmp(state, _GAME));
    return state;
}

layer_state_t layer_state_set_user(layer_state_t state) {
    rgblight_set_layer_state(3, layer_state_cmp(state, _MOUSE));
    rgblight_set_layer_state(4, layer_state_cmp(state, _LOWER));
    rgblight_set_layer_state(5, layer_state_cmp(state, _RAISE));
    rgblight_set_layer_state(6, layer_state_cmp(state, _ADJUST));
    return state;
}
/// End Enact Colors~ /// }}}
